package net.lesscoding.shop.controller;

import net.lesscoding.shop.common.Result;
import net.lesscoding.shop.entity.Goods;
import net.lesscoding.shop.entity.GoodsNumberLog;
import net.lesscoding.shop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author eleven
 * @date 2024/6/14 9:12
 * @apiNote
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;
    @PostMapping("/reduceGoodsNum")
    public Result reduceGoodsNum(@RequestBody GoodsNumberLog goodsLog) {
        return goodsService.reduceGoodsNum(goodsLog);
    }

    @GetMapping("/{goodsId}")
    public Result<Goods> getById(@PathVariable("goodsId") Long goodsId) {
        Goods goods = goodsService.getById(goodsId);
        return Result.success(goods);
    }
}
